<template>
	<view class="container">
		<view>
			<uni-popup ref="popup" type="top" background-color="#fff">
				<view class="popup-content">
					<case-query-form @query="handleQuery"></case-query-form>
				</view>
			</uni-popup>
		</view>
		<view class="uni-list">
			<case-list-content :list-data="listData" :rows="rows" @click="itemClick">
			</case-list-content>
		</view>
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
	</view>
</template>

<script>
	import { getDicts } from "@/api/system/dict/data";
	import { getEpsCarInfoList } from '@/api/eps/epsCarInfo.js'
	export default {
		data(){
			return {
				queryParams:{
					caseCode:"",
					reportTime:[]
				},
				page:1,
				size:10,
				total:0,
				listData: [],
				isCancel: 0,
				rows:[{
					labelName:"车牌号",
					valueName:"clCph"
				},{
					labelName:"车辆类型",
					valueName:"clLx"
				},{
					labelName:"所属单位",
					valueName:"orgName"
				}],
				reload: false,
				status: 'more',
				adpid: '',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				carType:[],
				// 目标纬度
				latitude: '',
				// 目标经度
				longitude: '',
				// 目标地址名称
				name: '',
				// 我自己的位置经纬度（百度地图需要传入自己的经纬度进行导航）
				selfLocation: {
					latitude: '',
					longitude: ''
				}
			}
		},
		methods:{
			getList() {
				uni.showLoading({
					title:"加载中"
				})
				if (this.total && !this.reload) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				if(this.page == 1){
					this.reload = true;
					this.listData = [];
				}
				if(this.reload){
					uni.stopPullDownRefresh();
				}
				this.queryParams.pageSize = this.size;
				this.queryParams.pageNum = this.page;
				console.log(this.queryParams);
				getEpsCarInfoList(this.queryParams).then(res => {
					uni.hideLoading();
					if(res.code == 200){
						//console.log(JSON.stringify(res));
						let list = res.rows;
						this.total = res.total;
						list.forEach(item => {
							if(item.clLx){
								this.carType.forEach(opt => {
									if(opt.dictValue == item.clLx){
										item.clLx = opt.dictLabel;
									}
								})
							}
						})
						this.listData = this.reload ? list : this.listData.concat(list);
						this.reload = false;
						//判断是否最后一页
						if(this.size*this.page>=res.total){
							this.status="noMore"
						}
					}
				})
			},
			itemClick(item){
				console.log(item)
				uni.navigateTo({
					url: "../../common/webview/index?url="+encodeURI("pages/monitor/car-monitor"),
					events: {
						//监听选点事件，得到坐标 详细地址
						acceptDataFromOpenedPage:function(data){
							console.log(JSON.stringify(data));
						}
					}
				})
			},
			handleQuery(params){
				this.queryParams = params;
				this.page = 1;
				this.getList();
				this.$refs.popup.close();
			},
			handleRepeat(){
				this.queryParams = {};
			},
		},
		
		onLoad(param) {
			console.log(param)
			//车辆类型
			getDicts("eps_car_type").then(response => {
				this.carType = response.data;
			});
			let _this = this;
			this.page = 1;
			this.getList();
		},
		onNavigationBarButtonTap : function (e) {
			this.$refs.popup.open()
		},
		onPullDownRefresh(){
			this.page = 1;
			this.getList();
		},
		onReachBottom(){
			this.page++;
			if(this.listData.length < this.total){
				this.status = 'more';
			}else{
				this.status = 'noMore';
				return;
			}
			this.getList();
		}
	}
</script>

<style lang="scss">
	.popup-content {
		padding: 15px;
		height: 500px;
		background-color: #fff;
	}
	.nav-btn{
		margin-right: 15px;
	}
</style>